<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html id="htmlId">
<head>
    <title>Coverage Report :: LauncherSmokeTest</title>
    <style type="text/css">
        @import "../../.css/coverage.css";
    </style>
</head>

<body>
<div class="header"></div>

<div class="content">
    <div class="breadCrumbs">
        [ <a href="../../index.html">all classes</a> ]
        [ <a href="../index.html">nl.tudelft.jpacman</a> ]
    </div>

    <h1>Coverage Summary for Class: LauncherSmokeTest (nl.tudelft.jpacman)</h1>

    <table class="coverageStats">
        <tr>
            <th class="name">Class</th>
            <th class="coverageStat
">
                Class, %
            </th>
            <th class="coverageStat
">
                Method, %
            </th>
            <th class="coverageStat
">
                Line, %
            </th>
        </tr>
        <tr>
            <td class="name">LauncherSmokeTest</td>
            <td class="coverageStat">
  <span class="percent">
    0%
  </span>
                <span class="absValue">
    (0/ 1)
  </span>
            </td>
            <td class="coverageStat">
  <span class="percent">
    0%
  </span>
                <span class="absValue">
    (0/ 5)
  </span>
            </td>
            <td class="coverageStat">
  <span class="percent">
    0%
  </span>
                <span class="absValue">
    (0/ 29)
  </span>
            </td>
        </tr>

    </table>

    <br/>
    <br/>


    <div class="sourceCode"><i>1</i>&nbsp;package nl.tudelft.jpacman;
        <i>2</i>&nbsp;
        <i>3</i>&nbsp;import static org.assertj.core.api.Assertions.assertThat;
        <i>4</i>&nbsp;
        <i>5</i>&nbsp;import nl.tudelft.jpacman.board.Direction;
        <i>6</i>&nbsp;import nl.tudelft.jpacman.game.Game;
        <i>7</i>&nbsp;import nl.tudelft.jpacman.level.Player;
        <i>8</i>&nbsp;import org.junit.jupiter.api.AfterEach;
        <i>9</i>&nbsp;import org.junit.jupiter.api.BeforeEach;
        <i>10</i>&nbsp;import org.junit.jupiter.api.Test;
        <i>11</i>&nbsp;
        <i>12</i>&nbsp;/**
        <i>13</i>&nbsp; * Smoke test launching the full game,
        <i>14</i>&nbsp; * and attempting to make a number of typical moves.
        <i>15</i>&nbsp; * &lt;p&gt;
        <i>16</i>&nbsp; * This is &lt;strong&gt;not&lt;/strong&gt; a &lt;em&gt;unit&lt;/em&gt; test -- it is an
        end-to-end test
        <i>17</i>&nbsp; * trying to execute a large portion of the system&#39;s behavior directly from the
        <i>18</i>&nbsp; * user interface. It uses the actual sprites and monster AI, and hence
        <i>19</i>&nbsp; * has little control over what is happening in the game.
        <i>20</i>&nbsp; * &lt;p&gt;
        <i>21</i>&nbsp; * Because it is an end-to-end test, it is somewhat longer
        <i>22</i>&nbsp; * and has more assert statements than what would be good
        <i>23</i>&nbsp; * for a small and focused &lt;em&gt;unit&lt;/em&gt; test.
        <i>24</i>&nbsp; *
        <i>25</i>&nbsp; * @author Arie van Deursen, March 2014.
        <i>26</i>&nbsp; */
        <b class="nc"><i>27</i>&nbsp;public class LauncherSmokeTest {</b>
        <i>28</i>&nbsp;
        <i>29</i>&nbsp; private Launcher launcher;
        <i>30</i>&nbsp;
        <i>31</i>&nbsp; /**
        <i>32</i>&nbsp; * Launch the user interface.
        <i>33</i>&nbsp; */
        <i>34</i>&nbsp; @BeforeEach
        <i>35</i>&nbsp; void setUpPacman() {
        <b class="nc"><i>36</i>&nbsp; launcher = new Launcher();</b>
        <b class="nc"><i>37</i>&nbsp; launcher.launch();</b>
        <i>38</i>&nbsp; }
        <i>39</i>&nbsp;
        <i>40</i>&nbsp; /**
        <i>41</i>&nbsp; * Quit the user interface when we&#39;re done.
        <i>42</i>&nbsp; */
        <i>43</i>&nbsp; @AfterEach
        <i>44</i>&nbsp; void tearDown() {
        <b class="nc"><i>45</i>&nbsp; launcher.dispose();</b>
        <i>46</i>&nbsp; }
        <i>47</i>&nbsp;
        <i>48</i>&nbsp; /**
        <i>49</i>&nbsp; * Launch the game, and imitate what would happen in a typical game.
        <i>50</i>&nbsp; * The test is only a smoke test, and not a focused small test.
        <i>51</i>&nbsp; * Therefore it is OK that the method is a bit too long.
        <i>52</i>&nbsp; *
        <i>53</i>&nbsp; * @throws InterruptedException Since we&#39;re sleeping in this test.
        <i>54</i>&nbsp; */
        <i>55</i>&nbsp; @SuppressWarnings({&quot;magicnumber&quot;, &quot;methodlength&quot;, &quot;PMD.JUnitTestContainsTooManyAsserts&quot;})
        <i>56</i>&nbsp; @Test
        <i>57</i>&nbsp; void smokeTest() throws InterruptedException {
        <b class="nc"><i>58</i>&nbsp; Game game = launcher.getGame();</b>
        <b class="nc"><i>59</i>&nbsp; Player player = game.getPlayers().get(0);</b>
        <i>60</i>&nbsp;
        <i>61</i>&nbsp; // start cleanly.
        <b class="nc"><i>62</i>&nbsp; assertThat(game.isInProgress()).isFalse();</b>
        <b class="nc"><i>63</i>&nbsp; game.start();</b>
        <b class="nc"><i>64</i>&nbsp; assertThat(game.isInProgress()).isTrue();</b>
        <b class="nc"><i>65</i>&nbsp; assertThat(player.getScore()).isZero();</b>
        <i>66</i>&nbsp;
        <i>67</i>&nbsp; // get points
        <b class="nc"><i>68</i>&nbsp; game.move(player, Direction.EAST);</b>
        <b class="nc"><i>69</i>&nbsp; assertThat(player.getScore()).isEqualTo(10);</b>
        <i>70</i>&nbsp;
        <i>71</i>&nbsp; // now moving back does not change the score
        <b class="nc"><i>72</i>&nbsp; game.move(player, Direction.WEST);</b>
        <b class="nc"><i>73</i>&nbsp; assertThat(player.getScore()).isEqualTo(10);</b>
        <i>74</i>&nbsp;
        <i>75</i>&nbsp; // try to move as far as we can
        <b class="nc"><i>76</i>&nbsp; move(game, Direction.EAST, 7);</b>
        <b class="nc"><i>77</i>&nbsp; assertThat(player.getScore()).isEqualTo(60);</b>
        <i>78</i>&nbsp;
        <i>79</i>&nbsp; // move towards the monsters
        <b class="nc"><i>80</i>&nbsp; move(game, Direction.NORTH, 6);</b>
        <b class="nc"><i>81</i>&nbsp; assertThat(player.getScore()).isEqualTo(120);</b>
        <i>82</i>&nbsp;
        <i>83</i>&nbsp; // no more points to earn here.
        <b class="nc"><i>84</i>&nbsp; move(game, Direction.WEST, 2);</b>
        <b class="nc"><i>85</i>&nbsp; assertThat(player.getScore()).isEqualTo(130);</b>
        <i>86</i>&nbsp;
        <b class="nc"><i>87</i>&nbsp; move(game, Direction.NORTH, 2);</b>
        <i>88</i>&nbsp;
        <i>89</i>&nbsp; // Sleeping in tests is generally a bad idea.
        <i>90</i>&nbsp; // Here we do it just to let the monsters move.
        <b class="nc"><i>91</i>&nbsp; Thread.sleep(500L);</b>
        <i>92</i>&nbsp;
        <i>93</i>&nbsp; // we&#39;re close to monsters, this will get us killed.
        <b class="nc"><i>94</i>&nbsp; move(game, Direction.WEST, 10);</b>
        <b class="nc"><i>95</i>&nbsp; move(game, Direction.EAST, 10);</b>
        <i>96</i>&nbsp;// assertThat(player.isAlive()).isTrue();
        <i>97</i>&nbsp;
        <b class="nc"><i>98</i>&nbsp; game.stop();</b>
        <b class="nc"><i>99</i>&nbsp; assertThat(game.isInProgress()).isFalse();</b>
        <i>100</i>&nbsp; }
        <i>101</i>&nbsp;
        <i>102</i>&nbsp; /**
        <i>103</i>&nbsp; * Make number of moves in given direction.
        <i>104</i>&nbsp; *
        <i>105</i>&nbsp; * @param game The game we&#39;re playing
        <i>106</i>&nbsp; * @param dir The direction to be taken
        <i>107</i>&nbsp; * @param numSteps The number of steps to take
        <i>108</i>&nbsp; */
        <i>109</i>&nbsp; public static void move(Game game, Direction dir, int numSteps) {
        <b class="nc"><i>110</i>&nbsp; Player player = game.getPlayers().get(0);</b>
        <b class="nc"><i>111</i>&nbsp; for (int i = 0; i &lt; numSteps; i++) {</b>
        <b class="nc"><i>112</i>&nbsp; game.move(player, dir);</b>
        <i>113</i>&nbsp; }
        <i>114</i>&nbsp; }
        <i>115</i>&nbsp;}
    </div>
</div>

<div class="footer">

    <div style="float:right;">generated on 2023-04-25 16:45</div>
</div>
</body>
</html>
